package com.wq.ui.coms;

import java.awt.Font;
import java.awt.FontFormatException;
import java.io.File;
import java.io.IOException;

/**
 * 字体控制类
 *
 * @author wq
 * 2020/12/19 - 17:43
 */
public class FontCreater {
    private static Font defaultFont;
    private static Font rightFont;//对勾

    public static Font getDefalut() {
        if (defaultFont == null) {
            try {
                String path = Thread.currentThread().getContextClassLoader().getResource("./font/default.ttf").getPath();
                java.io.FileInputStream fi = new java.io.FileInputStream(new File(path));
                java.io.BufferedInputStream fb = new java.io.BufferedInputStream(fi);
                defaultFont = Font.createFont(Font.TRUETYPE_FONT, fb);
                defaultFont = defaultFont.deriveFont(Font.BOLD, 30);
            } catch (FontFormatException | IOException e) {
                e.printStackTrace();
            }
        }
        return defaultFont;
    }

    public static Font getRightFont() {
        if (rightFont == null) {
            try {
                String path = Thread.currentThread().getContextClassLoader().getResource("./font/STXINGKA.ttf").getPath();
                java.io.FileInputStream fi = new java.io.FileInputStream(new File(path));
                java.io.BufferedInputStream fb = new java.io.BufferedInputStream(fi);
                rightFont = Font.createFont(Font.TRUETYPE_FONT, fb);
                rightFont = rightFont.deriveFont(Font.BOLD, 30);
            } catch (FontFormatException | IOException e) {
                e.printStackTrace();
            }
        }
        return rightFont;
    }


}
